package com.jxd.project.wzgl.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jxd.project.wzgl.dto.DeleteGoodsDTO;
import com.jxd.project.wzgl.dto.GoodsDTO;
import com.jxd.project.wzgl.dto.QueryGoodsDTO;
import com.jxd.project.wzgl.dto.QueryGoodsLogDTO;
import com.jxd.project.menu.model.Warehouse;
import com.jxd.project.wzgl.service.IGoodsLogService;
import com.jxd.project.wzgl.service.IGoodsService;
import com.jxd.project.wzgl.service.IWareHouseKeeperService;
import com.jxd.project.wzgl.service.IWarehouseService;
import com.jxd.project.wzgl.vo.WarehouseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName GoodsController
 * @Description TODO
 * @Author 刘成
 * @Date 2025/10/1 20:21
 * @Version 1.0
 */
@RestController
@RequestMapping("/lc")
public class GoodsController {
    @Autowired
    @Qualifier("goodsServiceImpl")
    private IGoodsService goodsService;
    @Autowired
    @Qualifier("goodsLogServiceImpl")
    private IGoodsLogService goodsLogService;
    @Autowired
    @Qualifier("wareHouseKeeperServiceImpl")
    private IWareHouseKeeperService wareHouseKeeperService;
    @Autowired
    @Qualifier("warehouseServiceImpl")
    private IWarehouseService warehouseService;


    @RequestMapping("/addGoods")
    public String addGoods(@RequestBody GoodsDTO goodsDTO){
        boolean result = goodsService.addGoods(goodsDTO);
        return result ? "success" : "fail";
    }

    @RequestMapping("/updateGoods")
    public String updateGoods(@RequestBody GoodsDTO goodsDTO){
        boolean result = goodsService.updateGoods(goodsDTO);
        return result ? "success" : "fail";
    }

    @RequestMapping("/deleteGoods")
    public String deleteGoods(@RequestBody DeleteGoodsDTO deleteGoodsDTO){
        boolean result = goodsService.deleteGoods(deleteGoodsDTO);
        return result ? "success" : "fail";
    }

    @RequestMapping("/selectGoodsByWarehouseId")
    public Map<String,Object> selectGoodsByWarehouseId(@RequestBody QueryGoodsDTO queryGoodsDTO){
        return goodsService.getGoodsByWarehouseId(queryGoodsDTO);
    }

    @RequestMapping("/getGoodsLogWithQueryGoodsLogDTO")
    public Map<String,Object> getGoodsLogWithQueryGoodsLogDTO(@RequestBody QueryGoodsLogDTO queryGoodsLogDTO){
        return goodsLogService.getGoodsLogWithQueryGoodsLogDTO(queryGoodsLogDTO);
    }

    @RequestMapping("/queryHouseKeeperByHouseId")
    public List<WarehouseVO> queryHouseKeeperByHouseId(int warehouseId){
        return wareHouseKeeperService.queryHouseKeeperByHouseId(warehouseId);
    }

    @RequestMapping("/queryWarehouseByEmpNo")
    public List<WarehouseVO> queryWarehouseByEmpNo(String empNo){
        return wareHouseKeeperService.queryWarehouseByEmpNo(Integer.parseInt(empNo));
    }

    @RequestMapping("/queryWarehouse")
    public List<Warehouse> queryWarehouse(){
        QueryWrapper<Warehouse> qw = new QueryWrapper<>();
        qw.eq("type","仓库");
        //按value字段升序
        qw.orderByAsc("value");
        return warehouseService.list(qw);
    }

    @RequestMapping("/getBorrowType")
    public List<Warehouse> getBorrowType(){
        QueryWrapper<Warehouse> qw = new QueryWrapper<>();
        qw.eq("type","借用类型");
        qw.orderByAsc("value");
        return warehouseService.list(qw);
    }
}
